public class Solution5 {
    public String longestPalindrome(String s) {
        String res = "";
        for(int i = 0;i < s.length();i++){
            
            String single = getString(s,i,i);
            String dou = getString(s,i,i+1);
            //更新长度
            res = (single.length() > res.length())? single : res;
            res = (dou.length() > res.length())? dou : res;
        }
        return res;
    }
    //(给定中点)得到最长回文子串
    public String getString(String s , int left , int right){
            while(0 <= left && right < s.length() && s.charAt(left) == s.charAt(right)){
                left--;
                right++;
            }
            return s.substring(left + 1, right);
    }
}